//package com.luanye.enjoy.flowable.task;
//
//import com.alibaba.fastjson.JSON;
//import com.luanye.enjoy.config.SpringUtilConfig;
//import com.luanye.enjoy.dto.SmsDTO;
//import com.luanye.enjoy.entity.VillageUser;
//import com.luanye.enjoy.service.UserService;
//import com.luanye.enjoy.service.VillageService;
//import com.luanye.enjoy.service.VillageUserService;
//import org.flowable.engine.delegate.DelegateExecution;
//import org.flowable.engine.delegate.JavaDelegate;
//import org.springframework.amqp.core.Message;
//import org.springframework.amqp.core.MessageProperties;
//import org.springframework.amqp.rabbit.core.RabbitTemplate;
//import org.springframework.data.geo.Point;
//import org.springframework.data.redis.core.StringRedisTemplate;
//
//import static com.luanye.enjoy.constants.MQConst.SMS_EXCHANGE;
//import static com.luanye.enjoy.constants.RedisConst.VILLAGE_GEO_KEY;
//import static com.luanye.enjoy.constants.SmsConst.TEMPLATE_VILLAGE_SUCCESS;
//
//public class CompleteTask implements JavaDelegate {
//
//    @Override
//    public void execute(DelegateExecution execution) {
//        VillageService villageService = SpringUtilConfig.getBean(VillageService.class);
//        VillageUserService villageUserService = SpringUtilConfig.getBean(VillageUserService.class);
//        RabbitTemplate rabbitTemplate = SpringUtilConfig.getBean(RabbitTemplate.class);
//        UserService userService = SpringUtilConfig.getBean(UserService.class);
//        StringRedisTemplate stringRedisTemplate = SpringUtilConfig.getBean(StringRedisTemplate.class);
//
//        Long userid = execution.getVariable("userid", Long.class);
//        Long village_id = execution.getVariable("village_id", Long.class);
//        String villageName = execution.getVariable("villageName", String.class);
//        String phone = execution.getVariable("phone", String.class);
//        String x = execution.getVariable("x",String.class);
//        String y = execution.getVariable("y",String.class);
//
//        //修改乡村增加标志
//        villageService.update().setSql("is_check = 1")
//                .eq("id", village_id).update();
//
//
//        //乡村用户表加人
//        villageUserService.save(new VillageUser(userid, village_id));
//        //修改用户铭牌
//        userService.update()
//                .setSql("title = " + village_id + "村长").eq("id", userid).update();
//        //发送短信
//        SmsDTO dto = new SmsDTO(
//                phone,
//                new String[]{villageName},
//                TEMPLATE_VILLAGE_SUCCESS
//        );
//
//        rabbitTemplate.convertAndSend(SMS_EXCHANGE, "*", new Message(JSON.toJSONBytes(dto), new MessageProperties()));
//
//        //初始化位置
//        stringRedisTemplate.opsForGeo().add(VILLAGE_GEO_KEY, new Point(Double.valueOf(x), Double.valueOf(y)), village_id.toString());
//    }
//}
